package com.aizhixin.lab.project.course.service;

import com.aizhixin.lab.common.core.DataValidity;
import com.aizhixin.lab.common.utils.PageJdbcUtil;
import com.aizhixin.lab.company.entity.Classes;
import com.aizhixin.lab.company.entity.User;
import com.aizhixin.lab.company.repository.ClassesRepository;
import com.aizhixin.lab.company.repository.UserRepository;
import com.aizhixin.lab.project.course.domain.*;
import com.aizhixin.lab.project.course.entity.*;
import com.aizhixin.lab.project.course.repository.*;
import com.aizhixin.lab.project.course.vo.ProjectAppraisalVo;
import com.aizhixin.lab.project.course.vo.ProjectDailyPaperVo;
import com.aizhixin.lab.project.course.vo.ProjectGroupLeaderVo;
import com.aizhixin.lab.project.course.vo.ProjectMemberEvaluatingVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import sun.reflect.generics.repository.ClassRepository;

import javax.jws.soap.SOAPBinding;
import java.math.BigDecimal;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.*;
import java.util.stream.Collectors;

@Slf4j
@Service
@Transactional
public class ProjectReplyService {
    @Autowired
    private ProjectReplyRepository projectReplyRepository;
    @Autowired
    private PageJdbcUtil pageJdbcUtil;
    @Autowired
    private ProjectGroupScoreRepository projectGroupScoreRepository;
    @Autowired
    private ProjectPeopleEvaluatingRepository projectPeopleEvaluatingRepository;
    @Autowired
    private GradeRatioRepository gradeRatioRepository;
    @Autowired
    private ProjectClassStuRepository stuRepository;
    @Autowired
    private ProjectGroupTaskRepository groupTaskRepository;
    @Autowired
    private ProjectGroupRepository groupRepository;
    @Autowired
    private TeacherModuleTaskRepository teacherModuleTaskRepository;
    @Autowired
    private UserRepository userRepository;
    @Autowired
    private ClassesRepository classRepository;
    public List<GroupGradeDomain> exportGrade(String projectId, Boolean isComplexTable) {
        List<GroupGradeDomain> projectGradeDomain = new ArrayList<>();
        List<ProjectPeopleEvaluating> evaluatingList = projectPeopleEvaluatingRepository.findByProjectIdAndDeleteFlag(projectId, DataValidity.VALID.getState());
        Map<String, BigDecimal> map = new HashMap<>();
        evaluatingList.forEach(item -> {
            map.put(item.getId(), new BigDecimal(item.getWeight()));
        });
        List<GradeRatio> gradeRatioList = gradeRatioRepository.findAll();
        List<ProjectGroup> projectGroupList = groupRepository.findByProjectIdAndDeleteFlag(projectId, DataValidity.VALID.getState());
        for (ProjectGroup projectGroup : projectGroupList) {
            //获取小组答辩平均分
            GroupGradeDomain groupGradeDomain = new GroupGradeDomain();
            groupGradeDomain.setGroupName(projectGroup.getGroupName());
            List<StuGradeDomain> groupGradeDomainList = new ArrayList<>();
            List<ProjectReply> groupReplyList = projectReplyRepository.findByProjectIdAndReplyObjectIdAndDeleteFlag(projectId, projectGroup.getId(), DataValidity.VALID.getState());
            Set<Long> groupCreated = groupReplyList.stream().map(ProjectReply::getCreatedBy).collect(Collectors.toSet());
            BigDecimal bigDecimal1 = new BigDecimal(0);
            for (ProjectReply projectReply : groupReplyList) {
                bigDecimal1 = new BigDecimal(projectReply.getScore()).multiply(map.get(projectReply.getEvaluatingId())).add(bigDecimal1);
            }
            if (bigDecimal1.intValue()!=0) {
                bigDecimal1 = bigDecimal1.divide(new BigDecimal(groupCreated.size()), 2, BigDecimal.ROUND_HALF_UP);
            }
            List<ProjectClassStu> stuList = stuRepository.findByGroupIdAndDeleteFlagAndProjectId(projectGroup.getId(), DataValidity.VALID.getState(), projectId);
            for (ProjectClassStu projectClassStu : stuList) {
                StuGradeDomain stuGradeDomain = new StuGradeDomain();
                User one = userRepository.findOne(projectClassStu.getStuId());
                if (!Objects.isNull(one)){
                    stuGradeDomain.setStuName(one.getName());
                    Classes classes = classRepository.findById(one.getClassId());
                    if (!Objects.isNull(classes)){
                        stuGradeDomain.setClassName(classes.getName());
                    }

                }
                List<KeyValueDomain> keyValueDomainList = new ArrayList<>();
                stuGradeDomain.setGroupName(projectGroup.getGroupName());
//                stuGradeDomain.setStuId(projectClassStu.getStuId());
                //获取已完成的任务平均分
                Integer asDouble = 0;
                List<ProjectGroupTask> groupTaskList = groupTaskRepository.findByProjectIdAndStuIdAndDeleteFlagAndTaskGradeNotNull(projectId, projectClassStu.getStuId(), DataValidity.VALID.getState());
                    for (ProjectGroupTask item : groupTaskList) {
                        asDouble += item.getTaskGrade();
                        KeyValueDomain keyValueDomain = new KeyValueDomain();
                        if (isComplexTable) {
                            TeacherModuleTask moduleTask = teacherModuleTaskRepository.findByIdAndDeleteFlag(item.getTaskId(), DataValidity.VALID.getState());
                            if (!Objects.isNull(moduleTask)) {
                                keyValueDomain.setKey(moduleTask.getTaskName());
                                keyValueDomain.setValue(Double.valueOf(item.getTaskGrade()));
                                keyValueDomainList.add(keyValueDomain);
                            }
                        }
                    }


                stuGradeDomain.setKeyValueDomainList(keyValueDomainList);

//                double asDouble = groupTaskList.stream().mapToInt(ProjectGroupTask::getTaskGrade).average().getAsDouble();
                BigDecimal bigDecimal = new BigDecimal(asDouble);
                if (groupTaskList.size()==0){
                    stuGradeDomain.setTaskGrade(new BigDecimal(0));

                }else {
                    stuGradeDomain.setTaskGrade(bigDecimal.divide(new BigDecimal(groupTaskList.size()),2, BigDecimal.ROUND_HALF_UP));
                }
                //获取答辩平均分
                List<ProjectReply> stuReplyList = projectReplyRepository.findByProjectIdAndReplyObjectIdAndDeleteFlag(projectId, projectClassStu.getStuId().toString(), DataValidity.VALID.getState());
                BigDecimal bigDecimal2 = new BigDecimal(0);
                Set<Long> collect = stuReplyList.stream().map(ProjectReply::getCreatedBy).collect(Collectors.toSet());
                for (ProjectReply projectReply : stuReplyList) {
                    bigDecimal2 = new BigDecimal(projectReply.getScore()).multiply(map.get(projectReply.getEvaluatingId())).add(bigDecimal1);
                }
                if (bigDecimal2.intValue()!=0) {
                    bigDecimal2 = bigDecimal2.divide(new BigDecimal(collect.size()), 2, BigDecimal.ROUND_HALF_UP);
                }
                stuGradeDomain.setReplyGrade(bigDecimal1.add(bigDecimal2));
                //获取考勤平均分
                String truantSql = "SELECT COUNT(c.id) FROM c_stu_sign_in c LEFT JOIN c_release_sign_in r ON c.sign_in_id=r.id WHERE r.course_id='" + projectId + "' AND c.stu_id=" + projectClassStu.getStuId() + " AND c.status=0";
                String lateSql = "SELECT COUNT(c.id) FROM c_stu_sign_in c LEFT JOIN c_release_sign_in r ON c.sign_in_id=r.id WHERE r.course_id='" + projectId + "' AND c.stu_id=" + projectClassStu.getStuId() + " AND c.status=2";
                Integer lateNum = pageJdbcUtil.getCountInt(lateSql);
                Integer truantNum = pageJdbcUtil.getCountInt(truantSql);
                stuGradeDomain.setLateNum(lateNum);
                stuGradeDomain.setTruantNum(truantNum);
                stuGradeDomain.setSignGrade(100 - truantNum * 3 - lateNum);

                groupGradeDomainList.add(stuGradeDomain);
            }
            groupGradeDomain.setGroupGradeDomainList(groupGradeDomainList);
            projectGradeDomain.add(groupGradeDomain);
        }
        return projectGradeDomain;
    }

    RowMapper<ProjectDailyPaperVo> dailyPaperVoRowMapper = new RowMapper<ProjectDailyPaperVo>() {

        @Override
        public ProjectDailyPaperVo mapRow(ResultSet rs, int rowNum) throws SQLException {

            ProjectDailyPaperVo domain = new ProjectDailyPaperVo();
            domain.setId(rs.getString("id"));
            domain.setCheckStatus(rs.getInt("check_status"));
            domain.setCheckSuggest(rs.getString("check_suggest"));
            domain.setGiveMark(rs.getDouble("give_mark"));
            domain.setCreatedBy(rs.getString("created_by"));
            domain.setCreatedDate(rs.getString("created_date"));
            domain.setCheckSuggest(rs.getString("check_suggest"));
            domain.setTomorrowTask(rs.getString("tomorrow_task"));
            domain.setAccomplishTask(rs.getString("accomplish_task"));
            domain.setTodayReap(rs.getString("today_reap"));
            domain.setName(rs.getString("name"));
            domain.setProblemsAndTactics(rs.getString("problems_and_tactics"));
            return domain;
        }
    };

    RowMapper<ProjectGroupLeaderVo> leaderVoRowMapper = new RowMapper<ProjectGroupLeaderVo>() {
        @Override
        public ProjectGroupLeaderVo mapRow(ResultSet rs, int rowNum) throws SQLException {
            ProjectGroupLeaderVo domain = new ProjectGroupLeaderVo();
            domain.setName(rs.getString("name"));
            domain.setScore(rs.getDouble("score"));
            domain.setEvaluatingId(rs.getString("evaluating_id"));
            return domain;
        }
    };

    RowMapper<ProjectMemberEvaluatingVo> projectMemberEvaluatingVoRowMapper = new RowMapper<ProjectMemberEvaluatingVo>() {
        @Override
        public ProjectMemberEvaluatingVo mapRow(ResultSet rs, int rowNum) throws SQLException {

            ProjectMemberEvaluatingVo domain = new ProjectMemberEvaluatingVo();
            domain.setCode(rs.getString("code"));
            domain.setScore(rs.getDouble("score"));
            domain.setRole(rs.getString("role"));
            domain.setName(rs.getString("name"));
            domain.setUserName(rs.getString("user_name"));
            domain.setId(rs.getString("id"));
            domain.setUserId(rs.getLong("userId"));
            domain.setCreatedBy(rs.getString("created_by"));
            return domain;
        }
    };
    RowMapper<ProjectAppraisalVo> projectAppraisalVoRowMapper = new RowMapper<ProjectAppraisalVo>() {
        @Override
        public ProjectAppraisalVo mapRow(ResultSet rs, int rowNum) throws SQLException {
            ProjectAppraisalVo domain = new ProjectAppraisalVo();
            domain.setName(rs.getString("name"));
            domain.setScore(rs.getDouble("score"));
            domain.setId(rs.getString("id"));
            domain.setUserId(rs.getString("userId"));
            domain.setUserName(rs.getString("user_name"));
            domain.setRole(rs.getString("role"));
            domain.setCreatedBy(rs.getString("created_by"));
            return domain;
        }
    };

    public void save(ProjectReplyListDomain domain) {
        if (domain.getProjectReplyDomainList().size() > 0) {
            ProjectReplyDomain data = domain.getProjectReplyDomainList().get(0);
            projectReplyRepository.deleteByReleaseProjectReplyIdAndReplyObjectIdAndCreatedByAndGroupId(data.getReleaseProjectReplyId(), data.getReplyObjectId(), data.getCreatedBy(), data.getGroupId());
        }
        for (ProjectReplyDomain data : domain.getProjectReplyDomainList()) {
//            projectReplyRepository.deleteByProjectIdAndReplyObjectIdAndCreatedByAndGroupId(data.getProjectId(),data.getReplyObjectId(),data.getCreatedBy(),data.getGroupId());
            ProjectReply projectReply = new ProjectReply();
            BeanUtils.copyProperties(data, projectReply);
            projectReply.setId(UUID.randomUUID().toString());
            projectReply.setCreatedDate(new Date());
            projectReply.setDeleteFlag(DataValidity.VALID.getState());
            projectReplyRepository.save(projectReply);
        }
    }

    public Map findTeamSynthesizeMark(QueryProjectReplyDomain domain) {
        //查询当前测评维度
        List<ProjectPeopleEvaluating> peopleEvaluating = projectPeopleEvaluatingRepository.findByProjectIdAndDeleteFlagAndType(domain.getProjectId(), 0, domain.getReplyType());
        //查询老师打分
        List<ProjectAppraisalVo> projectAppraisalVoListTea = this.findTeamSynthesizeMarkTea(domain);
        //学生打分
        List<ProjectAppraisalVo> projectAppraisalVoListStu = this.findTeamSynthesizeMarkStu(domain);
        List<ProjectAppraisalVo> scoreList = new ArrayList<>();
        /*projectAppraisalVoListTea.forEach(tea -> {
                peopleEvaluating.forEach(weight->{
                        if (weight.getId().equals(tea.getId())){
                            ProjectAppraisalVo projectAppraisalVo = new ProjectAppraisalVo();
                            projectAppraisalVo.setScore(DoubleUtil.mul(tea.getScore(),weight.getWeight()));
                            projectAppraisalVo.setName(tea.getName());
                            scoreList.add(projectAppraisalVo);
                        }
                });
        });

            projectAppraisalVoListStu.forEach(stu -> {
                peopleEvaluating.forEach(weight->{
                        if (weight.getId().equals(stu.getId())){
                            ProjectAppraisalVo projectAppraisalVo = new ProjectAppraisalVo();
                            projectAppraisalVo.setScore(DoubleUtil.mul(stu.getScore(),weight.getWeight()));
                            projectAppraisalVo.setName(stu.getName());
                            scoreList.add(projectAppraisalVo);
                        }
                });
            });*/
        scoreList.addAll(projectAppraisalVoListTea);
        scoreList.addAll(projectAppraisalVoListStu);
        /*projectAppraisalVoListTea.forEach(tea->{
            projectAppraisalVoListStu.forEach(stu -> {
                    if (tea.getId().equals(stu.getId())){
                        ProjectAppraisalVo projectAppraisalVo = new ProjectAppraisalVo();
                        projectAppraisalVo.setScore(DoubleUtil.add(stu.getScore(),tea.getScore()));
                        projectAppraisalVo.setName(stu.getName());
                        scoreList.add(projectAppraisalVo);
                    }
            });
        });*/
        List list = new ArrayList();
        Map<String, List<ProjectAppraisalVo>> scoreMap = scoreList.stream().collect(Collectors.groupingBy(ProjectAppraisalVo::getName));
        Map<String, List<ProjectAppraisalVo>> userNameMap = scoreList.stream().collect(Collectors.groupingBy(ProjectAppraisalVo::getUserName));

        for (String key : scoreMap.keySet()) {
            List<ProjectAppraisalVo> value = scoreMap.get(key);
            Double score = value.stream().mapToDouble(ProjectAppraisalVo::getScore).sum();
            Map map = new HashMap();
            map.put("name", key);
            map.put("score", score);
            list.add(map);
        }
        double avgScore = scoreList.size() == 0 ? 0 : scoreList.stream().mapToDouble(ProjectAppraisalVo::getScore).sum();
        Map map = new HashMap();
        Set<String> teaName = projectAppraisalVoListTea.stream().map(ProjectAppraisalVo::getUserName).collect(Collectors.toSet());
        Set<String> stuName = projectAppraisalVoListStu.stream().map(ProjectAppraisalVo::getUserName).collect(Collectors.toSet());
        BigDecimal tea = new BigDecimal(0.7);
        BigDecimal stu = new BigDecimal(0.3);
        BigDecimal bigDecimal = new BigDecimal(avgScore);
        bigDecimal.divide(stu, 2, BigDecimal.ROUND_HALF_UP);
        try {
            map.put("avgScore", bigDecimal.divide(tea.multiply(new BigDecimal(teaName.size())).add((stu.multiply(new BigDecimal(stuName.size())))), 2, BigDecimal.ROUND_HALF_UP).doubleValue());
        }catch (ArithmeticException e){
            map.put("avgScore", "0");
        }
        map.put("appraisaScore", list);
        ProjectGroupScore groupScore = new ProjectGroupScore();
        groupScore.setGroupId(domain.getGroupId());
        groupScore.setReleaseProjectReplyId(domain.getReleaseProjectReplyId());
        groupScore.setProjectId(domain.getProjectId());
        groupScore.setId(UUID.randomUUID().toString());
        groupScore.setScore((Double) map.get("avgScore"));
        projectGroupScoreRepository.deleteByReleaseProjectReplyIdAndGroupId(domain.getReleaseProjectReplyId(), domain.getGroupId());
        projectGroupScoreRepository.save(groupScore);
        return map;
    }


    public List<ProjectDailyPaperVo> findProjectDailyPaper(QueryProjectWeeklyDomain domain) {
        String sql = "SELECT a.id,a.name,a.give_mark,a.accomplish_task,a.today_reap,a.problems_and_tactics,a.tomorrow_task,a.check_status,a.check_suggest,a.created_date,b.NAME as created_by FROM t_project_daily_daper a LEFT JOIN t_user b ON a.created_by = b.id where a.project_id = '" + domain.getProjectId() + "' and a.group_id = '" + domain.getGroupId() + "'";
        String orderBy = "order by a.check_time desc limit 0,10";
        if (domain.getCreatedBy() != null) {
            sql += "and a.created_by = " + domain.getCreatedBy() + " " + orderBy;
        } else {
            sql += " " + orderBy;
        }
        List<ProjectDailyPaperVo> projectDailyPaperVoList = pageJdbcUtil.getInfo(sql, dailyPaperVoRowMapper);
        return projectDailyPaperVoList;
    }

    public List<ProjectGroupLeaderVo> findMarkMemberStu(QueryProjectReplyDomain domain) {
        String sql = "";
        if (domain.getStuId() == null) {
            sql = "SELECT sum(a.score * ( SELECT weight_ratio FROM t_project_reply_weight WHERE weight_type = 1 ) *  (select weight from t_project_people_evaluating where id = a.evaluating_id)) AS score,a.evaluating_id,b.NAME FROM t_project_reply a LEFT JOIN t_user b ON a.created_by = b.id where a.reply_type = '" + domain.getReplyType() + "' and  b.role = 'student' and a.release_project_reply_id = '" + domain.getReleaseProjectReplyId() + "' and a.group_id = '" + domain.getGroupId() + "' GROUP BY a.created_by";
        } else {
            sql = "SELECT sum(a.score * ( SELECT weight_ratio FROM t_project_reply_weight WHERE weight_type = 1 ) *  (select weight from t_project_people_evaluating where id = a.evaluating_id)) AS score,a.evaluating_id,b.NAME FROM t_project_reply a LEFT JOIN t_user b ON a.created_by = b.id where a.reply_type = 1 and  b.role = 'student' and a.release_project_reply_id = '" + domain.getReleaseProjectReplyId() + "' and a.group_id = '" + domain.getGroupId() + "' and a.reply_object_id = '" + domain.getStuId() + "' GROUP BY a.created_by";
        }
        List<ProjectGroupLeaderVo> projectGroupLeaderVoList = pageJdbcUtil.getInfo(sql, leaderVoRowMapper);
        return projectGroupLeaderVoList;
    }

    public List<ProjectGroupLeaderVo> findMarkMemberTea(QueryProjectReplyDomain domain) {
        String sql = "";
        if (domain.getStuId() == null) {
            sql = "SELECT sum(a.score * ( SELECT weight_ratio FROM t_project_reply_weight WHERE weight_type = 2 ) *  (select weight from t_project_people_evaluating where id = a.evaluating_id)) AS score,a.evaluating_id,b.NAME FROM t_project_reply a LEFT JOIN t_user b ON a.created_by = b.id where a.reply_type = '" + domain.getReplyType() + "' and  b.role = 'teacher' and a.release_project_reply_id = '" + domain.getReleaseProjectReplyId() + "' and a.group_id = '" + domain.getGroupId() + "' GROUP BY a.created_by";
        } else {
            sql = "SELECT sum(a.score * ( SELECT weight_ratio FROM t_project_reply_weight WHERE weight_type = 2 ) *  (select weight from t_project_people_evaluating where id = a.evaluating_id)) AS score,a.evaluating_id,b.NAME FROM t_project_reply a LEFT JOIN t_user b ON a.created_by = b.id where a.reply_type = 1 and  b.role = 'teacher' and a.release_project_reply_id = '" + domain.getReleaseProjectReplyId() + "' and a.group_id = '" + domain.getGroupId() + "' and a.reply_object_id = '" + domain.getStuId() + "' GROUP BY a.created_by";
        }
        List<ProjectGroupLeaderVo> projectGroupLeaderVoList = pageJdbcUtil.getInfo(sql, leaderVoRowMapper);
        return projectGroupLeaderVoList;
    }

    public List<ProjectAppraisalVo> findTeamSynthesizeMarkStu(QueryProjectReplyDomain domain) {
        String sql = "";
        if (domain.getReplyType() == 1) {
            sql += "select a.score * (select weight_ratio from t_project_reply_weight where weight_type = 1) * ( SELECT weight FROM t_project_people_evaluating WHERE id = a.evaluating_id ) as score,b.id AS created_by,c.text as name,c.id,a.reply_object_id as userId, b.name as user_name,d.role from t_project_reply a left join t_user b on a.created_by = b.id  left join t_project_people_evaluating c on a.evaluating_id = c.id left join c_project_class_stu d on a.reply_object_id = d.stu_id where a.reply_type = 1 and b.role = 'student' and a.release_project_reply_id = '" + domain.getReleaseProjectReplyId() + "' and a.group_id = '" + domain.getGroupId() + "' and a.reply_object_id = '" + domain.getStuId() + "' GROUP BY a.evaluating_id,a.created_by";
        } else {
            sql += "select a.score * (select weight_ratio from t_project_reply_weight where weight_type = 1) * ( SELECT weight FROM t_project_people_evaluating WHERE id = a.evaluating_id ) as score,b.id AS created_by,c.text as name,c.id,a.reply_object_id as userId, b.name as user_name,d.role from t_project_reply a left join t_user b on a.created_by = b.id  left join t_project_people_evaluating c on a.evaluating_id = c.id left join c_project_class_stu d on a.reply_object_id = d.stu_id where a.reply_type = 2 and b.role = 'student'  and a.release_project_reply_id = '" + domain.getReleaseProjectReplyId() + "' and a.group_id = '" + domain.getGroupId() + "' GROUP BY a.evaluating_id,a.created_by";
        }
        List<ProjectAppraisalVo> projectAppraisalVoList = pageJdbcUtil.getInfo(sql, projectAppraisalVoRowMapper);
        return projectAppraisalVoList;
    }

    public List<ProjectAppraisalVo> findTeamSynthesizeMarkTea(QueryProjectReplyDomain domain) {
        String sql = "";
        if (domain.getReplyType() == 1) {
            sql += "select a.score * (select weight_ratio from t_project_reply_weight where weight_type = 2) * ( SELECT weight FROM t_project_people_evaluating WHERE id = a.evaluating_id ) as score,b.id AS created_by,c.text as name,c.id,a.reply_object_id as userId, b.name as user_name,d.role from t_project_reply a left join t_user b on a.created_by = b.id  left join t_project_people_evaluating c on a.evaluating_id = c.id left join c_project_class_stu d on a.reply_object_id = d.stu_id  where a.reply_type = 1 and b.role = 'teacher' and a.release_project_reply_id = '" + domain.getReleaseProjectReplyId() + "' and a.group_id = '" + domain.getGroupId() + "' and a.reply_object_id = '" + domain.getStuId() + "' GROUP BY a.evaluating_id,a.created_by";
        } else {
            sql += "select a.score * (select weight_ratio from t_project_reply_weight where weight_type = 2) * ( SELECT weight FROM t_project_people_evaluating WHERE id = a.evaluating_id ) as score,b.id AS created_by,c.text as name,c.id,a.reply_object_id as userId, b.name as user_name,d.role from t_project_reply a left join t_user b on a.created_by = b.id  left join t_project_people_evaluating c on a.evaluating_id = c.id left join c_project_class_stu d on a.reply_object_id = d.stu_id where a.reply_type = 2  and b.role = 'teacher' and a.release_project_reply_id = '" + domain.getReleaseProjectReplyId() + "' and a.group_id = '" + domain.getGroupId() + "' GROUP BY a.evaluating_id,a.created_by";
        }

        List<ProjectAppraisalVo> projectAppraisalVoList = pageJdbcUtil.getInfo(sql, projectAppraisalVoRowMapper);
        return projectAppraisalVoList;
    }

    public List<ProjectMemberEvaluatingVo> findMemberEvaluating(QueryProjectReplyDomain domain) {
        String sql = "select a.score as score,c.text as name, b.name as user_name,c.code,d.role from t_project_reply a left join t_user b on a.reply_object_id = b.id  left join t_project_people_evaluating c on a.evaluating_id = c.id left join c_project_class_stu d on a.reply_object_id = d.stu_id where   b.role = 'student' and a.project_id = '" + domain.getProjectId() + "' and a.group_id = '" + domain.getGroupId() + "'  GROUP BY a.evaluating_id ";
        List<ProjectMemberEvaluatingVo> projectGroupLeaderVoList = pageJdbcUtil.getInfo(sql, projectMemberEvaluatingVoRowMapper);
        return projectGroupLeaderVoList;
    }

    public List<ProjectMemberEvaluatingVo> findMemberEvaluatingRiteStu(QueryProjectReplyDomain domain) {
        String sql = "select a.score*(select weight_ratio from t_project_reply_weight where weight_type = 1) * ( SELECT weight FROM t_project_people_evaluating WHERE id = a.evaluating_id ) as score,b.id AS created_by,c.text as name,c.id,a.reply_object_id as userId, (select name from t_user where id = a.reply_object_id) as user_name,c.code,d.role from t_project_reply a left join t_user b on a.created_by = b.id  left join t_project_people_evaluating c on a.evaluating_id = c.id left join c_project_class_stu d on a.reply_object_id = d.stu_id where a.reply_type = 1 AND b.role = 'student'  and a.release_project_reply_id = '" + domain.getReleaseProjectReplyId() + "' and a.group_id = '" + domain.getGroupId() + "'  GROUP BY a.evaluating_id,a.reply_object_id";
        List<ProjectMemberEvaluatingVo> projectGroupLeaderVoList = pageJdbcUtil.getInfo(sql, projectMemberEvaluatingVoRowMapper);
        return projectGroupLeaderVoList;
    }

    public List<ProjectMemberEvaluatingVo> findMemberEvaluatingRiteTea(QueryProjectReplyDomain domain) {
        String sql = "select a.score*(select weight_ratio from t_project_reply_weight where weight_type = 2) * ( SELECT weight FROM t_project_people_evaluating WHERE id = a.evaluating_id ) as score,b.id AS created_by,c.text as name,a.reply_object_id as userId,c.id, (select name from t_user where id = a.reply_object_id) as user_name,c.code,d.role from t_project_reply a left join t_user b on a.created_by = b.id  left join t_project_people_evaluating c on a.evaluating_id = c.id left join c_project_class_stu d on a.reply_object_id = d.stu_id where a.reply_type = 1 AND b.role = 'teacher'  and a.release_project_reply_id = '" + domain.getReleaseProjectReplyId() + "' and a.group_id = '" + domain.getGroupId() + "'  GROUP BY a.evaluating_id,a.reply_object_id";
        List<ProjectMemberEvaluatingVo> projectGroupLeaderVoList = pageJdbcUtil.getInfo(sql, projectMemberEvaluatingVoRowMapper);
        return projectGroupLeaderVoList;
    }

}
